# -*- coding: UTF-8 -*-
import numpy as np
import math
import config

LAT = 41.90965503379327
LON = 12.49423224029439
WAIT = 20

def calc_loc(lon,lat,distance,amuith=0):
    RE = 6371.393 * 1000
    re =RE*math.cos(lat/180*math.pi)
    lon2=lon+distance*math.sin(amuith/180*math.pi)/(re*2*math.pi)*360
    lat2=lat+distance*math.cos(amuith/180*math.pi)/(re*2*math.pi)*360
    return lon2,lat2

def square():
    bian = round(pow(config.EDGE_NODE_NUM,0.5))
    if bian%2 == 0:
        ab_b = round(bian/2)
        above_dis = ab_b * config.node_interval + config.node_interval/2
        _,lat_max = calc_loc(LON,LAT,above_dis,0)
        _,lat_min = calc_loc(LON,LAT,above_dis,180)
        bel_b = round(bian/2)
        left_dis = bel_b * config.node_interval + config.node_interval/2
        lon_min,_ = calc_loc(LON,LAT, left_dis,-90)
        lon_max,_ = calc_loc(LON,LAT, left_dis,90)
    else:
        ab_b = round(bian/2)
        above_dis = ab_b * config.node_interval
        _,lat_max = calc_loc(LON,LAT,above_dis,0)
        _,lat_min = calc_loc(LON,LAT,above_dis,180)
        bel_b = round(bian/2)
        left_dis = bel_b * config.node_interval
        lon_min,_ = calc_loc(LON,LAT,left_dis,-90)
        lon_max,_ = calc_loc(LON,LAT,left_dis,90)
    return lat_min,lon_min,lat_max,lon_max

def generateNode(lat_min,lon_min,lat_max,lon_max):
    bian = round(pow(config.EDGE_NODE_NUM,0.5))
    devides = bian + 1
    lat_part = (lat_max-lat_min)/devides
    lon_part = (lon_max-lon_min)/devides
    nodes = np.zeros((bian,bian,2))
    nodes_list = []
    for i in range(bian):
        for j in range(bian):
            nodes[i][j][0] = lat_min + lat_part*(i+1)
            nodes[i][j][1] = lon_min + lon_part*(j+1)
            nodes_list.append([lat_min + lat_part*(i+1),lon_min + lon_part*(j+1)])
    return nodes,nodes_list


if __name__=='__main__':
   pass